#include <bits/stdc++.h>
using namespace std;

const int N = 10010;

vector<int> v[N], temp, ans;
bool vis[N];
int mm = -1;

void dfs(int x, int h) {

    if (h > mm)  mm = h, ans = temp;
    for (auto c : v[x]) {
        temp.push_back(c);
        dfs(c, h + 1);
        temp.pop_back();
    }
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int cnt;
        cin >> cnt;
        while (cnt--) {
            int x;
            cin >> x;
            v[i].push_back(x);
            vis[x] = true;
        }
        sort(v[i].begin(), v[i].end());
    }
    int flag;
    for (int i = 0; i < n; i++)
        if (!vis[i]) {
            flag = i, dfs(i, 1);
            break;
        }

    cout << mm << endl << flag;
    for (auto c : ans) cout << ' ' << c;

    return 0;
}
